# 1. 字符串的创建
a = 'I'
b = "我爱你"
c = "My name is 'Tom' "
d = '''
    I 
      love 
          you!
'''
e = """
  *
 ***
******
 ***
  *
"""

'''
print(a)
print(b)
print(c)
print(d)
print(e)
'''

# # ord() 将字符转化成对应的 Unicode 码
# # chr() 把十进制装换成对应的字符
# print(ord('我'))
# print(chr(65))

# a = '我爱你'
# aa = a.encode()
# print(aa)
# b = aa.decode()
# print(b)

# 不换行打印
# print('I',end=' ')
# print('Love',end='\t#')
# print('You',end='!!!')

# 从控制台中输入文本
# age = input('请输入你的年龄:')
# print('你的年龄:',age)

# a = 'agdcbcegalgahjbaldnbajgakaldvagajl'
# # index(str) 返回从左到右第一次str的位置
# index1 =  a.index('g')
# print(index1)
# # 如果 str 是多字符的话，那么返回该字符串的第一个字节出现的位置
# index2 = a.index('bc')
# print(index2)
#
# # rindex(str) 返回从有到左第一次str的位置
# index3 = a.rindex('g')
# print(index3)
# index4 = a.rindex('dv')
# print(index4)
#
# # len(str) 返回 str 的字符串长度
# print(len(a))
#
# # a.count(str) 返回 a字符串中出现 str 的次数
# print(a.count('a'))

# a.replace(str1,str2) 把 a 字符 str1 字符串 转成 str2，
# 并且会生成一个新的 字符串，旧的字符串不会修改.
# a = 'agdcbcegalgahjbaldnbajgakaldvagajl'
# b = a.replace('a','我')
# print(a)
# print(b)
#
# # maketrans() 用来生成映射表，
# # translate() 根据映射表中的定义的对应关系转换字符串并替换其中的字符
# table = ''.maketrans('0123456789','零一二三四五六七八九')
# print(table)
# tel = 'Tel:2951751015'.translate(table)
# print(tel)


# a = 'abcdefghijklmnopqrstuvwxyz'
# # 切片的三个数字都是整数
# # 1. [:] 获取整个字符串
# print(a[:])
# # 2. [start:] 从 start 位置开始获取
# print(a[2:])
# # 3. [:end] 到 end-1 位置截止
# print(a[:len(a)-1])
# # 即使end > len(a) 也没有事 -> 自动获得全部的字符串
# print(a[:len(a)+2])
# # [start:end] 从 start位置开始到end-1位置截止
# print(a[2:len(a)-1])
# # [start:end:step] 从 start位置开始到end-1位置，步长为step
# print(a[2:len(a):2])
#
# # 三个参数是负数的情况
# print(a[-3:])
# print(a[-8:-3])
# print(a[::-1])

# split()分割和join()合并

# a = " I love  Yo u !"
# # 默认按照空白字符进行分割
# print(a.split())
#
# # 也可以指定字符来分割
# print(a.split('o'))
#
# # join() 函数用来拼接
# a = ['I','Love','Y','ou','!!!']
# print(' '.join(a))

# a = '我爱你'
# b = a + '!!!'
# print(a)
# print(b)
#
# # 也可以这样写
# a = '我爱你'
# print(a)
# a = a + '!!!'
# print(a)

# # 测试 join 和 + 的效率
# import time
# time1 = time.time()
# a = ''
# for _ in range(100000):
#     a = a + 'Jerry'
# time2 = time.time()
# print('使用+进行拼接的效率:',str(time2-time1))
#
# time3 = time.time()
# li = []
# for _ in range(100000):
#     li.append('Jerry')
# a = ''.join(li)
# time4 = time.time()
# print('使用join进行拼接的效率:',str(time4-time3))

# a = 'I am jerry'
# b = 'I am jerry'
# print(id(a))
# print(id(b))
# print(a is b)
#
# print(a == b)
# name = 'Jerry'
# age = 19
# print('My name is {0}.I am {1} years old'.format(name,age))
# # 或者是
# print(f'My name is {name}.I am {age} years old')
#
# print(f'{'123':*>8}')

# a = ('桃树、杏树、梨树，你不让我，我不让你，都开满了花赶趟儿。红的像火，粉的像霞，白的像雪。花里带着甜味儿；闭了眼，树上仿佛已经满是桃儿、'
#      '杏儿、梨儿。花下成千成百的蜜蜂嗡嗡地闹着，大小的蝴蝶飞来飞去。野花遍地是：杂样儿，'
#      '有名字的，没名字的，散在草丛里，像眼睛，像星星，还眨呀眨的')
# # 常用的查找方法
# print(a.startswith('桃树'))
# print(a.endswith('星星'))
# print(a.find('树'))
# print(a.rfind('树'))

# a = 'I love YOu !'
# print(a.capitalize())
# print(a.title())
# print(a.upper())
# print(a.lower())
# print(a.swapcase())

print('123abc我'.isalnum())
print('abc我'.isalpha())
print('123'.isdigit())
print('I AM A STUDENT'.isupper())
print('i love you'.islower())
print('\n\t'.isspace())